/**
 * @note 设置高级查询面板上偏移量
 * @param element1：参照物元素
 * @param element2：偏移目标元素
 * @author 吴义迪
 * @create_time 2016-11-22
 */
function setAdvancedQueryDivTop1(element1, element2){
	var height = element1.offset().top;
	var divHeight = element2.outerHeight();
	if((height + divHeight) > $(window).height()-5){
		height = height - ((height + divHeight)-($(window).height()-5));
	}
	element2.css("top", height+"px");
}

/**
 * @note 地图工具栏鼠标移入移出监听事件
 * @author 吴义迪
 * @create_time 2016-12-26
 */
function toolMouseFunc(e){
	e = e || window.event;
	var type = e.data.type;
	var flag = e.data.flag;
	if(type == "enter"){
		if(flag == "toolHide"){
			$("#tool_hide").attr("src", "resources/images/tool_hide_checked.png");
		}else if(flag == "title"){
			setAdvancedQueryDivTop1($("#header_menus_title"), $("#header_menus_title_tips"));
			$("#header_menus_title_tips").show();
		}else if(flag == "fullImage"){
			setAdvancedQueryDivTop1($("#header_menus_fullImage"), $("#header_menus_fullImage_tips"));
			$("#header_menus_fullImage_tips").show();
		}else if(flag == "fullScreen"){
			setAdvancedQueryDivTop1($("#header_menus_fullScreen"), $("#header_menus_fullScreen_tips"));
			$("#header_menus_fullScreen_tips").show();
		}else if(flag == "layer"){
			setAdvancedQueryDivTop1($("#header_menus_layer"), $("#header_menus_layer_tips"));
			$("#header_menus_layer_tips").show();
		}else if(flag == "mask"){
			setAdvancedQueryDivTop1($("#header_menus_mask"), $("#header_menus_mask_tips"));
			$("#header_menus_mask_tips").show();
		}else if(flag == "surface"){
			setAdvancedQueryDivTop1($("#header_menus_surface"), $("#header_menus_surface_tips"));
			$("#header_menus_surface_tips").show();
		}else if(flag == "rang"){
			setAdvancedQueryDivTop1($("#header_menus_rang"), $("#header_menus_rang_tips"));
			$("#header_menus_rang_tips").show();
		}else if(flag == "query"){
			if(!$("#draw_tool").is(":visible")){
				setAdvancedQueryDivTop1($("#header_menus_query"), $("#draw_tool"));
				$("#draw_tool").css("right", "43px");
				$("#draw_tool").show(200);
			}
		}
	}else if(type == "leave"){
		if(flag == "toolHide"){
			$("#tool_hide").attr("src", "resources/images/tool_hide.png");
		}else if(flag == "title"){
			$("#header_menus_title_tips").hide();
		}else if(flag == "fullImage"){
			$("#header_menus_fullImage_tips").hide();
		}else if(flag == "fullScreen"){
			$("#header_menus_fullScreen_tips").hide();
		}else if(flag == "layer"){
			$("#header_menus_layer_tips").hide();
		}else if(flag == "mask"){
			$("#header_menus_mask_tips").hide();
		}else if(flag == "surface"){
			$("#header_menus_surface_tips").hide();
		}else if(flag == "rang"){
			$("#header_menus_rang_tips").hide();
		}
	}
}

/**
 * @note 画图工具栏鼠标移入移出监听事件
 * @author 吴义迪
 * @create_time 2017-07-17
 */
function drawToolMouseFunc(e){
	e = e || window.event;
	var type = e.data.type;
	if(type == "leave"){
		$("#draw_tool").hide(200);
	}
}

/**
 * @note 画图工具栏点击监听事件
 * @author 吴义迪
 * @create_time 2017-07-17
 */
function drawToolClickFunc(e){
	e = e || window.event;
	if(e.target.id == "draw_tool_jx"){
		mapAreaQuery("jx");
	}else if(e.target.id == "draw_tool_yx"){
		mapAreaQuery("yx");
	}else if(e.target.id == "draw_tool_dbx"){
		mapAreaQuery("dbx");
	}else if(e.target.id == "draw_tool_ry"){
		mapAreaQuery("ry");
	}else if(e.target.id == "draw_tool_remove"){
		bxfbExit();
	}
	$("#draw_tool").hide(200);
}

/**
 * @note 工具栏点击事件委托
 * @author 吴义迪
 * @create_time 2016-11-21
 */
function toolClickFunc(e){
	e = e || window.event;
	//底图
	if(e.target.id == "header_menus_layer"){
		setAdvancedQueryDivTop1($("#header_menus_layer"), $("#map_layer"));
		$("#map_layer").css("right", "43px");
		if($("#map_layer").is(":visible")){
			$("#map_layer").fadeOut(500);
		}else{
			$("#map_layer").fadeIn(500);
		}
	}
	//标题
	else if(e.target.id == "header_menus_title"){
		if(e.target.attributes.flag.nodeValue == "0"){
			$("#header_menus_title").attr("flag", "1");
			$("#header_menus_title").attr("src", "resources/images/header_menus_title_checked.png");
			$("#map_title").hide();
		}else if(e.target.attributes.flag.nodeValue == "1"){
			$("#header_menus_title").attr("flag", "0");
			$("#header_menus_title").attr("src", "resources/images/header_menus_title.png");
			$("#map_title").show();
		}
	}
	//长度量算
	else if(e.target.id == "header_menus_surface"){
		mapLengthMeasure();	//长度量算
	}
	//面积量算
	else if(e.target.id == "header_menus_rang"){
		mapAreaMeasure();	//面积量算
	}
	//下载图片产品
	else if(e.target.id == "header_menus_download"){
		downloadImgFunc();	//下载图片产品
	}
	//地图遮罩
	else if(e.target.id == "header_menus_mask"){
		if(e.target.attributes.flag.nodeValue == "0"){
			$("#header_menus_mask").attr("flag", "1");
			$("#header_menus_mask").attr("src", "resources/images/header_menus_mask_checked.png");
			openMapMask();
		}else if(e.target.attributes.flag.nodeValue == "1"){
			$("#header_menus_mask").attr("flag", "0");
			$("#header_menus_mask").attr("src", "resources/images/header_menus_mask.png");
			closeMapMask();
		}
	}
	//全屏
	else if(e.target.id == "header_menus_fullScreen"){
		if(e.target.attributes.flag.nodeValue == "0"){
			$("#header_menus_fullScreen").attr("flag", "1");
			$("#header_menus_fullScreen").attr("src", "resources/images/header_menus_fullScreen_off.png");
			fullSreenOn();
		}else if(e.target.attributes.flag.nodeValue == "1"){
			$("#header_menus_fullScreen").attr("flag", "0");
			$("#header_menus_fullScreen").attr("src", "resources/images/header_menus_fullScreen.png");
			fullSreenOff();
		}
	}
	//全幅显示
	else if(e.target.id == "header_menus_fullImage"){
		var b = Global.common.bounds.split(",");
		Global.common.map.zoomToExtent(new SuperMap.Bounds(parseFloat(b[0]),parseFloat(b[1]),parseFloat(b[2]),parseFloat(b[3])));
	}
	//工具栏隐藏
	else if(e.target.id == "tool_hide"){
		$("#draw_tool").hide(200);
		$("#tool_div").slideUp(500, function(){
			$("#header_menus_title_tool").attr("flag", "1");
			$("#header_menus_title_tool").attr("src", "resources/images/tool_checked.png");
		});
	}
	//工具栏
	else if(e.target.id == "header_menus_title_tool"){
		if($("#header_menus_title_tool").attr("flag") == "1"){
			$("#header_menus_title_tool").attr("flag", "0");
			$("#header_menus_title_tool").attr("src", "resources/images/tool.png");
			$("#tool_div").slideDown(500);
		}else if($("#header_menus_title_tool").attr("flag") == "0"){
			$("#draw_tool").hide(200);
			$("#tool_div").slideUp(500, function(){
				$("#header_menus_title_tool").attr("flag", "1");
				$("#header_menus_title_tool").attr("src", "resources/images/tool_checked.png");
			});
		}
	}
}

/**
 * @note 全屏
 * @author 吴义迪
 * @create_time 2016-07-02
 */
function fullSreenOn(){
	//F11全屏
	var docElm = window.parent.document.documentElement;  
    //W3C   
    if (docElm.requestFullscreen) {  
        docElm.requestFullscreen();  
    }  
    //FireFox   
    else if (docElm.mozRequestFullScreen) {  
        docElm.mozRequestFullScreen();  
    }  
    //Chrome等   
    else if (docElm.webkitRequestFullScreen) {  
        docElm.webkitRequestFullScreen();  
    }  
    //IE11   
    else if (elem.msRequestFullscreen) {  
        elem.msRequestFullscreen();  
    }
	
	$(".banner",window.parent.document).hide();
	$(".b_menu",window.parent.document).hide();
	$(".bar",window.parent.document).hide();
	if($(".banner",window.parent.document).is(":visible")){
		$("#indexIframe",window.parent.document).css({"width":($(window.parent.window).width()+"px"),"height":(($(window.parent.window).height() - $(".banner",window.parent.document).outerHeight()) - $(".bar",window.parent.document).outerHeight() + "px")});
	}else{
		$("#indexIframe",window.parent.document).css({"width":($(window.parent.window).width()+"px"),"height":($(window.parent.window).height() + "px")});
	}
	$("#map").outerWidth($(window).width());
	$("#map").outerHeight($(window).height());
	$(".zhfw .nav,.zhfw .bottom").css("height", $(".zhfw .bottom").outerHeight() + $(".banner",window.parent.document).outerHeight() + $(".b_menu",window.parent.document).outerHeight() + $(".bar",window.parent.document).outerHeight() + "px");
	$(".zhfw .con").css("height", $(".zhfw .con").outerHeight() + $(".banner",window.parent.document).outerHeight() + $(".b_menu",window.parent.document).outerHeight() + $(".bar",window.parent.document).outerHeight() + "px");
	
	$(".scroll-tip",window.parent.document).css("display", "none");
}

/**
 * @note 取消全屏
 * @author 吴义迪
 * @create_time 2016-07-02
 */
function fullSreenOff(){
	if (window.parent.document.exitFullscreen) {  
		window.parent.document.exitFullscreen();  
    }  
    else if (window.parent.document.mozCancelFullScreen) {  
    	window.parent.document.mozCancelFullScreen();  
    }  
    else if (window.parent.document.webkitCancelFullScreen) {  
    	window.parent.document.webkitCancelFullScreen();  
    }  
    else if (window.parent.document.msExitFullscreen) {  
    	window.parent.document.msExitFullscreen();  
    }
	
	$(".banner",window.parent.document).show();
	$(".b_menu",window.parent.document).show();
	$(".bar",window.parent.document).show();
	if($(".banner",window.parent.document).is(":visible")){
		$("#indexIframe",window.parent.document).css({"width":($(window.parent.window).width()+"px"),"height":(($(window.parent.window).height() - $(".banner",window.parent.document).outerHeight()) - $(".bar",window.parent.document).outerHeight() + "px")});
	}else{
		$("#indexIframe",window.parent.document).css({"width":($(window.parent.window).width()+"px"),"height":($(window.parent.window).height() + "px")});
	}
	$("#map").outerWidth($(window).width());
	$("#map").outerHeight($(window).height());
	$(".zhfw .nav,.zhfw .bottom").css("height", $(".zhfw .bottom").outerHeight() - $(".banner",window.parent.document).outerHeight() - $(".b_menu",window.parent.document).outerHeight() - $(".bar",window.parent.document).outerHeight() + "px");
	$(".zhfw .con").css("height", $(".zhfw .con").outerHeight() - $(".banner",window.parent.document).outerHeight() - $(".b_menu",window.parent.document).outerHeight() - $(".bar",window.parent.document).outerHeight() + "px");
	
	$(".scroll-tip",window.parent.document).css("display", "inline-block");
}

/**
 * @note 底图切换
 * @author 吴义迪
 * @create_time 2016-11-21
 */
function baseLayerChange(e){
	e = e || window.event;
	//退出底图切换面板
	if(e.target.id == "map_layer_exit"){
		$("#map_layer").fadeOut(500);
	}
	//底图切换至矢量图
	else if(e.target.id == "map_layer_vec" || e.target.id == "map_layer_vec_p"){
		changeBaseLayer("vec");
	}
	//底图切换至影像图
	else if(e.target.id == "map_layer_img" || e.target.id == "map_layer_img_p"){
		changeBaseLayer("img");
	}
	//底图切换至地形图
	else if(e.target.id == "map_layer_ter" || e.target.id == "map_layer_ter_p"){
		changeBaseLayer("ter");
	}
	//显示地名
	else if(e.target.id == "map_layer_placename_img1"){
		if(Global.common.layer1.getVisibility()){
			Global.common.layer4.setVisibility(true);
		}else if(Global.common.layer2.getVisibility()){
			Global.common.layer5.setVisibility(true);
		}else if(Global.common.layer3.getVisibility()){
			Global.common.layer6.setVisibility(true);
		}
		$("#map_layer_placename_img1").hide();
		$("#map_layer_placename_img2").show();
	}
	//隐藏地名
	else if(e.target.id == "map_layer_placename_img2"){
		Global.common.layer4.setVisibility(false);
		Global.common.layer5.setVisibility(false);
		Global.common.layer6.setVisibility(false);
		$("#map_layer_placename_img1").show();
		$("#map_layer_placename_img2").hide();
	}
	//显示边界
	else if(e.target.id == "map_layer_border_img1"){
		$("#map_layer_border_img1").hide();
		$("#map_layer_border_img2").show();
		Global.common.borderLayer.setVisibility(true);
	}
	//隐藏边界
	else if(e.target.id == "map_layer_border_img2"){
		$("#map_layer_border_img1").show();
		$("#map_layer_border_img2").hide();
		Global.common.borderLayer.setVisibility(false);
	}
}

/**
 * @note 开启遮罩图层
 * @author 吴义迪
 * @create_time 2017-03-06
 */
function openMapMask(){
	Global.common.maskLayer.setVisibility(true);
}

/**
 * @note 关闭遮罩图层
 * @author 吴义迪
 * @create_time 2017-03-06
 */
function closeMapMask(){
	Global.common.maskLayer.setVisibility(false);
}

/**
 * @note 窗口改变监听事件
 * @author 吴义迪
 * @create_time 2017-07-03
 */
function windowResizeFunc(){
	if($(".banner",window.parent.document).is(":visible")){
		$("#indexIframe",window.parent.document).css({"width":($(window.parent.window).width()+"px"),"height":(($(window.parent.window).height() - $(".banner",window.parent.document).outerHeight()) - $(".bar",window.parent.document).outerHeight() + "px")});
	}else{
		$("#indexIframe",window.parent.document).css({"width":($(window.parent.window).width()+"px"),"height":($(window.parent.window).height() + "px")});
	}
	$("#map").outerWidth($(window).width());
	$("#map").outerHeight($(window).height());
}

/**
 * @note 拖拽 - 鼠标按下
 * @author 吴义迪
 * @create_time 2017-07-05
 */
function dragMousedownFunc(e){
	e = e || window.event;
	flag = e.data.flag;
}

/**
 * @note 拖拽 - 移动
 * @author 吴义迪
 * @create_time 2017-07-05
 */
function dragMousemoveFunc(e){
	e = e || window.event;
}

/**
 * @note 拖拽 - 鼠标弹出
 * @author 吴义迪
 * @create_time 2017-07-05
 */
function dragMouseupFunc(e){
	e = e || window.event;
}

$("#yuZhiLegend-set").click(function(){
	if($("#setYuZhi_jcbj").is(":visible")){
		$("#setYuZhi_jcbj").hide();
	}else{
		$("#setYuZhi_jcbj").show();
	}
});

$("#zt_control1").click(function(){
	closeAllLayers();
	requestAllLayersByFid("1", "scrollContent");
});

$("#zt_control2").click(function(){
	closeAllLayers();
	requestAllLayersByFid("117", "scrollContent1");
});